/* 
 * Copyright (c) 2010, Avdhesh yadav.
 * http://www.avdheshyadav.com
 * Contact: avdhesh.yadav@gmail.com
 *
 * This library is free software; you can redistribute it and/or modify it under the terms
 * of the GNU Lesser General Public License as published by the Free Software Foundation,
 * either version 3 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this
 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 */

package com.avdy.p4j.sample.client.presenter;

import com.google.gwt.event.logical.shared.HasSelectionHandlers;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.user.client.ui.TreeItem;
import com.google.inject.Inject;

import net.customware.gwt.dispatch.client.DispatchAsync;
import net.customware.gwt.presenter.client.EventBus;
import net.customware.gwt.presenter.client.widget.WidgetContainerDisplay;
import net.customware.gwt.presenter.client.widget.WidgetContainerPresenter;

public class MainPresenter extends WidgetContainerPresenter<MainPresenter.Display>
{
	public interface Display extends WidgetContainerDisplay
	{
		public String ALL_BOOKS = "All Books";
		public String ISSUED_BOOKS = "Issued Books";
		public String ISSUE_BOOK = "Issue Book";
		public String RETURN_BOOK = "Return Book";
		
		public HasSelectionHandlers<TreeItem> getTree();
	}

	private DispatchAsync dispatcher;
	private BookListPresenter bookListPresenter;

	@Inject
	public MainPresenter(MainPresenter.Display display, DispatchAsync dispatcher, final EventBus bus, BookListPresenter bookListPresenter) 
	{
		super(display, bus,bookListPresenter);
		this.dispatcher = dispatcher;  
		this.bookListPresenter = bookListPresenter;
	}


	@Override
	protected void onBind()
	{  
		super.onBind();
		registerHandler(display.getTree().addSelectionHandler(new SelectionHandler<TreeItem>() {

			public void onSelection(SelectionEvent<TreeItem> event) 
			{
				TreeItem tItem = event.getSelectedItem();
				String item = (String)tItem.getText();
			}
		}));
	}
}